package com.example.demo.check;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.captcha.v20190722.CaptchaClient;
import com.tencentcloudapi.captcha.v20190722.models.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DescribeCaptchaResult
{
    @PostMapping("/sert")
    public  boolean ser( @RequestParam("randstr")String randstr, @RequestParam("ticket")String ticket) {
        String str = "";
        try {

            Credential cred = new Credential("AKID85mDNHuHNCkiQs3xbz7yYrtfpoZ4KL6c", "IK7fxzmKceR6WgaDbiZ9TXKrBH7i39za");

            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("captcha.tencentcloudapi.com");

            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);

            CaptchaClient client = new CaptchaClient(cred, "ap-beijing", clientProfile);

            String params = "{\"CaptchaType\":9,\"Ticket\":\"" + ticket + "\",\"UserIp\":\"127.0.0.1\",\"Randstr\":\"" + randstr + "\",\"CaptchaAppId\":2011491693,\"AppSecretKey\":\"01-s_iO4ySqMZd2v_feb11Q**\"}";

            DescribeCaptchaResultRequest req = DescribeCaptchaResultRequest.fromJsonString(params, DescribeCaptchaResultRequest.class);
            DescribeCaptchaResultResponse resp = client.DescribeCaptchaResult(req);

            str = DescribeCaptchaResultRequest.toJsonString(resp);

        } catch (TencentCloudSDKException e) {

            System.out.println(e.toString());
        }
        System.out.println(str);
        if (str.indexOf("OK") <0) {
            return false;
        } else {
            return true;
        }

    }
}